package ru.spb.osll.myfit.client.widget;

import java.util.LinkedList;
import java.util.List;

import ru.spb.osll.myfit.client.event.PageButtonEvent;
import ru.spb.osll.myfit.client.event.PageButtonEvent.PageButtonEventType;

import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.user.client.ui.Button;

public class PageButton extends Button {
  private List<PageButtonEventListener> m_listeners = new LinkedList<PageButtonEventListener>();
  private PageButtonEventType m_eventType;

  public PageButton(String title, String styleName, PageButtonEventType eventType) {
    super();
    m_eventType = eventType;
    setTitle(title);
    setStyleName(styleName);
    addClickHandler(new ClickHandler() {
      @Override
      public void onClick(ClickEvent arg0) {
        for (PageButtonEventListener listener : m_listeners) {
          listener.actionPerformed(new PageButtonEvent(m_eventType));
        }

      }
    });
  }

  public PageButton(String title, String styleName, PageButtonEventType eventType, PageButtonEventListener listener) {
    this(title, styleName, eventType);
    addPageEventListener(listener);
  }

  public void addPageEventListener(PageButtonEventListener listener) {
    m_listeners.add(listener);
  }

  public void removePageEventListener(PageButtonEventListener listener) {
    m_listeners.remove(listener);
  }
}
